package com.black.utils.config.loader;

import com.alibaba.fastjson2.JSONObject;
import com.black.utils.file.FileTypeEnum;
import com.black.utils.file.FileUtil;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.List;

/**
 * json配置加载器
 *
 * @author ylx
 */
public class JsonLoader extends Loader {

    @Override
    public JSONObject loadJsonConfig(String sourcePath) throws IOException {
        String content = FileUtil.loadFile(sourcePath, StandardCharsets.UTF_8);
        return JSONObject.parseObject(content);
    }

    @Override
    public List<FileTypeEnum> getTypes() {
        return Collections.singletonList(FileTypeEnum.JSON);
    }
}
